import 'package:flutter/material.dart';
import 'package:flutter_base/http/api.dart';

import '../../bean/knowledge/knowledge_detail_entity.dart';
import '../../bean/knowledge/knowlege_entity.dart';

///
/// @DIR_PATH：lib/viewmodel/knowledge
/// @TIME：2024/6/13 14:55
/// @AUTHOR：starr
///
class KnowledgeDetailViewModel with ChangeNotifier{

  List<Tab> tabs =[];
  int pageCount = 0;
  List<KnowledgeDetailItemDatas> itemList = [];

  void initTabs(List<KnowlegeDataChildren>? tabList){
    tabList?.forEach((element) { 
      tabs.add(Tab(text: element.name,));
    });
  }

  Future getKnowledgeDetail(bool loadMore,int? treeId)async{
    if(loadMore == true){
      pageCount ++;
    }else{
      pageCount --;
      itemList.clear();
    }
    var list = await Api.instance.getKnowledgeDetail(pageCount, treeId ?? 0);
    if(list?.isNotEmpty == true){
      itemList.addAll(list ?? []);
      notifyListeners();
    }else{
      if(loadMore == true && pageCount >0){
        pageCount --;
      }
    }
  }
}